package Business::Address::POBox;

use strict;
use warnings;
use String::BlackWhiteList;


our $VERSION = '0.06';


use base qw(Class::Accessor::Complex Class::Accessor::Constructor);


__PACKAGE__
    ->mk_constructor
    ->mk_object_accessors('String::BlackWhiteList' => 'matcher')
    ->mk_array_accessors(qw(blacklist whitelist));


use constant DEFAULTS => (
    blacklist => [
        'BOX',
        'POB',
        'POSTBOX',
        'POST',
        'POSTSCHACHTEL',
        'PO',
        'P O',
        'P O BOX',
        'P.O.',
        'P.O.B.',
        'P.O.BOX',
        'P.O. BOX',
        'P. O.',
        'P. O.BOX',
        'P. O. BOX',
        'POBOX',
        'PF',
        'P.F.',
        'POSTFACH',
        'POSTLAGERND',
        'POSTBUS'
    ],
    whitelist => [
        'Post Road',
        'Post Rd',
        'Post Street',
        'Post St',
        'Post Avenue',
        'Post Av',
        'Post Alley',
        'Post Drive',
        'Post Grove',
        'Post Walk',
        'Post Parkway',
        'Post Row',
        'Post Lane',
        'Post Bridge',
        'Post Boulevard',
        'Post Square',
        'Post Garden',
        'Post Strasse',
        'Post Allee',
        'Post Gasse',
        'Post Platz',
    ],
);


sub init {
    my $self = shift;
    $self->update;
}


sub update {
    my $self = shift;
    for ($self->matcher) {
        $_->set_is_literal_text;
        $_->blacklist($self->blacklist);
        $_->whitelist($self->whitelist);
        $_->update;
    }
}


sub is_pobox {
    my ($self, $text) = @_;
    !$self->matcher->valid($text);
}


1;


__END__

{% USE p = PodGenerated %}

=head1 NAME

{% p.package %} - Check whether an address looks like a P.O.Box

=head1 SYNOPSIS

    use {% p.package %};

    if ({% p.package %}->new->is_pobox($address)) {
        ...
    }

=head1 DESCRIPTION

This class tries to determine whether or not an string refers to a P.O. box.
This is sometims relevant if your business process, for legal reasons, needs a
real address and not a P.O. box.

It has predefined blacklists and whitelists that should catch most english and
german P.O. box addresses, but you can modify these lists with the methods
provided. Note that the entries are literal strings, not regular expressions.

=head1 METHODS

=over 4

{% p.write_methods %}

=item update

Call this method when you've changed the C<whitelist()> or the C<blacklist()>
so the matcher knows about the changes.

=item is_pobox

This is the central method of this class. It takes a string argument and
checks it against the whitelist and the blacklist. Returns a boolean value -
true if the string passes the whitelist or is at least not caught by the
blacklist, false if the string is caught by the blacklist.

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

